/**
 * Created with JetBrains WebStorm.
 * User: rekey
 * Date: 7/9/13
 * Time: 23:49
 * To change this template use File | Settings | File Templates.
 */
var crypto = require('crypto');

function md5(str) {
    var md5 = crypto.createHash('md5');
    md5.update(str);
    return md5.digest('hex');

}

function encrypt(str, secret) {
    var cipher = crypto.createCipher('aes192', secret);
    var enc = cipher.update(str, 'utf8', 'hex');
    enc += cipher.final('hex');
    return enc;
}

function decrypt(str, secret) {
    var decipher = crypto.createDecipher('aes192', secret);
    var dec = decipher.update(str, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

module.exports = {
    md5 : md5,
    encrypt : encrypt,
    decrypt : decrypt
};